package com.osmap.openstreetmap.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.osmap.openstreetmap.R;
import com.osmap.openstreetmap.json.FootmarkJson;

public class FootmarkAdapter extends BaseAdapter {
	private FootmarkJson mJson;
	private Context mContext;
	private LayoutInflater mLayoutInflater;

	public FootmarkAdapter(FootmarkJson mJson, Context mContext) {
		super();
		this.mJson = mJson;
		this.mContext = mContext;
		mLayoutInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mJson.list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mLayoutInflater.inflate(R.layout.item_footmark, null);
			holder.title = (TextView) convertView
					.findViewById(R.id.tv_footmark_title);
			holder.from = (TextView) convertView
					.findViewById(R.id.tv_footmark_from);
			holder.headImageView = (ImageView) convertView
					.findViewById(R.id.iv_footmark_img);
			holder.progressIv = (ImageView) convertView
					.findViewById(R.id.iv_footmark_progress);
            convertView.setTag(holder);
		}
		holder = (ViewHolder) convertView.getTag();
		holder.title.setText(mJson.list.get(position) != null ? mJson.list
		.get(position).title : "");
        holder.from.setText(mJson.list.get(position) != null ? mJson.list
                .get(position).fromString : "");
        if (mJson.list.get(position).progress==0){
            holder.progressIv.setImageResource(R.drawable.map_pro0);
        }else if (mJson.list.get(position).progress==1){
            holder.progressIv.setImageResource(R.drawable.map_pro50);
        }else if (mJson.list.get(position).progress==2){
            holder.progressIv.setImageResource(R.drawable.map_pro75);
        }else {
            holder.progressIv.setImageResource(R.drawable.map_pro100);
        }
        
		return convertView;
	}

	class ViewHolder {
		public TextView title;
		public TextView from;
		public ImageView headImageView;
		public ImageView progressIv;
	}
}
